import java.util.Random;
import java.io.OutputStream;
import java.io.IOException;

/**
 * This class is used to dump random content to a file
 * 
 * @author Ken Pu
 * @version 2012 Winter
 */
public class FileDump {
	/**
	 * Random data will be written to this output stream.
	 */
	private OutputStream out;
	/**
	 * This is a random number generator used to make
	 * the data
	 */
	private Random random;
	/**
	 * This is the constructor of the <i>FileDump</i> class.
	 * @param out This the output stream to write data to.
	 */
	public FileDump(OutputStream out) {
		this.out = out;
		this.random = new Random();
	}
	/**
	 * The <i>dump</i> method writes random data to the output stream.
	 * @param filesize This is an integer indicating the number of
	 *        bytes to be written to file.
	 * @return the number of milliseconds used to write the bytes
	 *         to the output file.
	 */
	public long dump(int filesize) throws IOException {
		int c;
		long startTime = System.currentTimeMillis();
		for(int i=0; i < filesize; i++) {
			c = 65 + random.nextInt(26);
			this.out.write(c);
		}
		return (System.currentTimeMillis() - startTime);
	}
}
